/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package toolz;

import javax.swing.AbstractAction;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.KeyStroke;

/**
 *
 * @author Bunkowski
 */
public class internalFrameKeyRegister {

    JInternalFrame ifr;

    public internalFrameKeyRegister(JInternalFrame ifr) {
        this.ifr = ifr;
    }

    public void register(String key, final AbstractButton button) {
        ifr.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
                KeyStroke.getKeyStroke(key), key);
        ifr.getRootPane().getActionMap().put(key, new AbstractAction() {

        	public static final long serialVersionUID = 1L;
        	
            public void actionPerformed(java.awt.event.ActionEvent e) {
                button.doClick();
//                if (button instanceof JToggleButton){
//                    if(button.isSelected()){
//                        button.setSelected(false);
//                    }
//                    else{
//                        button.setSelected(true);
//                    }
//
//                }
            }
        });

    }
}
